package com.lagou.myblog.controller;

import com.lagou.myblog.pojo.Article;
import com.lagou.myblog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class AtricleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/index")
    public String findArticleByPageInfo(@PageableDefault(page = 0, size = 3) Pageable pageable, Model model) {

        Page<Article> pageInfo = articleService.findArticleByPageInfo(pageable);
        List<Article> content = pageInfo.getContent();
        int pages = pageInfo.getTotalPages();
        model.addAttribute("list", content);
        model.addAttribute("pages", pages);
        model.addAttribute("current",pageInfo.getPageable().getPageNumber());

        return "client/index";
    }

}
